#include "Queue.hpp"
#include <time.h>



void* produce(void *argv)
{
  srand((unsigned)time(NULL));
  while(true)
  {
    sleep(1);
    int i = rand() % pthread_self();
    BQueue<int> *bq = (BQueue<int>*) argv;

    bq->push(i);
    std::cout << "product success " << i << std::endl;
  }
  return NULL;
}

void* consumer(void *argv)
{
  BQueue<int> *bq = (BQueue<int>*) argv;

  while(true)
  {
    int i = bq->pop();

    std::cout << "consumer get success " << i << std::endl;
  }
  return NULL;
}
int main()
{
  pthread_t t1, t2;

  BQueue<int> dq;
  pthread_create(&t1, NULL, produce, (void*)&dq);
  pthread_create(&t2, nullptr, consumer, (void*)&dq);


  pthread_join(t1, nullptr);
  pthread_join(t2, nullptr);

  return 0;
}
